package Client;
import javax.swing.*;

import Entities.Voter;
import Helpers.DBMethods;

import java.awt.*;
import java.awt.event.*;

//public class confirmVote implements ActionListener{
//	JFrame Nframe;
//	Boardcv mpanel;
//	Candidate candidate;
//	Voter vo;
//	Boardb boardb;
//	public confirmVote(Candidate candidate, Voter vo, Boardb boardb){
//		this.boardb = boardb;
//		this.candidate = candidate;
//		this.vo = vo;
//		Nframe = new JFrame("Online Voting System!");
//		Nframe.setSize(600,600);
//		Nframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//		Nframe.setResizable(true);
//		try {
//			mpanel = new Boardcv(candidate,vo);
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		Nframe.setContentPane(mpanel);	
//
//		JButton back = new JButton("Back");
//		back.setBounds(60, 350, 150, 30);
//		back.addActionListener(this);
//		back.setActionCommand("back");
//		mpanel.add(back);
//		back.setVisible(true);
//		Nframe.setVisible(false);
//	}
//
//	public void setV(){
//		Nframe.setVisible(true);
//	}
//
//	public void actionPerformed(ActionEvent e){
//		if(e.getActionCommand().equals("back")){
//			this.setV2();
//			boardb.setVisible(true);
//		}
//	}
//
//	private void setV2() {
//		Nframe.setVisible(false);
//	}
//}
@SuppressWarnings("serial")
class confirmReg extends JPanel implements ActionListener{	
	JLabel titleVote,password, captchaError;
	JTextField passwordT;
	JButton submit;
	OurCaptcha oc;
	DBMethods dbm = new DBMethods();
	Voter vo;
	JFrame mframe;
	JButton back = new JButton("Back");
	public confirmReg(Voter vo,JFrame mframe) {
		this.mframe = mframe;
		back.setBounds(40, 350, 85, 30);
		back.addActionListener(this);
		back.setActionCommand("back");
		add(back);
		this.vo = vo;
		setLayout(null); 	
		setBackground(Color.WHITE);	
		oc = new OurCaptcha();
		oc.setBounds(200, 300, 200, 160);
		add(oc);
		
		titleVote = new JLabel("Welcome to Voting System");
		submit = new JButton("Submit");
		password = new JLabel("New Password");
		passwordT = new JTextField();
		captchaError = new JLabel("Please retry entering the Capthca code");
		
		titleVote.setBounds(200,20,400,30);		// x/y/width/length
		password.setBounds(100,70,100,30);
		passwordT.setBounds(230,70,150,30);
		submit.setBounds(230, 110, 150, 30);
		captchaError.setBounds(400, 200, 300, 30);
		
		captchaError.setForeground(Color.RED);
		
		titleVote.setFont(new Font("Dialog", Font.PLAIN, 24));		

		submit.addActionListener(this);
		submit.setActionCommand("submit");	
		add(titleVote);
		add(submit);
		add(password);
		add(passwordT);
		add(captchaError);

		captchaError.setVisible(false);
		titleVote.setVisible(true);
		submit.setVisible(true);
		password.setVisible(true);
		passwordT.setVisible(true);
	}
	
	public void actionPerformed(ActionEvent e){	
		if(e.getActionCommand().equals("submit")){
			if(!oc.validateAnswer(oc.getText()))
				captchaError.setVisible(true);
			else
			{
				dbm.updateStudentByEmail(vo.getEmail(), passwordT.getText(),2);
				mframe.getContentPane().removeAll();
				mframe.repaint();
				vo.setActivated(2);
				vo.setPassword(passwordT.getText());
				JPanel p = new Boardb(vo,mframe);
				p.setBounds(0, 0, 600, 600);
				mframe.add(p);//.setV3();
				mframe.validate();
				mframe.repaint();
			}
			
		}
		else if(e.getActionCommand().equals("back")){
			mframe.getContentPane().removeAll();
			mframe.repaint();
			JPanel p = new Board(mframe);
			p.setBounds(0, 0, 600, 600);
			mframe.add(p);//.setV3();
			mframe.validate();
			mframe.repaint();
		}
	}
}

